//
//  LJCMusicListViewController.m
//  WZLProduct
//
//  Created by 陆静聪 on 16/3/22.
//  Copyright © 2016年 HaiTeng. All rights reserved.
//

#import "LJCMusicListViewController.h"
#import "LJCMusicListTableViewCell.h"

@interface LJCMusicListViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *rootTable;


@end

@implementation LJCMusicListViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createTable];
    
    LJCMusicModel *musicModel = _urlArr[_index];
    [self blackGroundView:musicModel.imgUrl];

    
}

- (void)createTable {
    _rootTable = [[UITableView alloc] initWithFrame:kScreen style:UITableViewStylePlain];
    _rootTable.delegate = self;
    _rootTable.dataSource = self;
    _rootTable.rowHeight = 80;
    _rootTable.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_rootTable];
    [_rootTable registerClass:[LJCMusicListTableViewCell class] forCellReuseIdentifier:@"LJCMusicListTableViewCell"];

}

#pragma mark - tableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _urlArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LJCMusicListTableViewCell *listCell = [tableView dequeueReusableCellWithIdentifier:@"LJCMusicListTableViewCell"];
    listCell.musicModel = _urlArr[indexPath.row];
    
    return listCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中
    //其他代码
    
    [_musicDelegate playMusic:indexPath];
    [self.navigationController popViewControllerAnimated:YES];
    
}

/** 毛玻璃 */
- (void)blackGroundView:(NSString *)imgUrl {
    
    NSURL *url = [NSURL URLWithString:imgUrl];
    
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    UIImage *image = [[UIImage imageWithData:data] boxblurImageWithBlur:0.9];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:image];
    
    
}

- (void)viewWillAppear:(BOOL)animated {
    [LJCMusicSwitch shareMusicSwitch].hidden = YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
